package com.yunc.modules.sys.handler;

import com.yunc.common.message.AbstractMessageHandler;
import com.yunc.modules.sys.entity.SysLog;
import com.yunc.modules.sys.service.ISysLogService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author taocongcong
 * @create 2018-10-30 14:22
 */
@Service
public class BaseLogHandler extends AbstractMessageHandler<SysLog> {

    private static final Logger logger = LogManager.getLogger(AbstractMessageHandler.class);

    @Autowired
    private ISysLogService sysLogService;

    public BaseLogHandler() {
        super("BASE_LOG_SYS", SysLog.class);
    }

    @Override
    public void handle(SysLog sysLog) {
        // 保存系统日志
        sysLogService.save(sysLog);
    }

    @Override
    public void handleFailed(SysLog obj) {
        StringBuilder sb = new StringBuilder();
        sb.append("msg:[").append(obj).append("], 超过失败次数，停止重试。");
        logger.warn(sb.toString());
    }
}
